package cn.ecnu.auction.engine;

import java.net.URLDecoder;
import java.util.Enumeration;

import org.json.JSONException; 
import org.json.JSONObject;


public class JsonRequestProcessor implements IRequestProcessor {

	public void processContext(Context context) {

		JSONObject jsonRequest = new JSONObject();

		Enumeration<?> enumeration = context.getRequest().getParameterNames();

		while (enumeration.hasMoreElements()) {

			String parameterName = enumeration.nextElement().toString();

			if (!parameterName.toLowerCase().equals("method")
					&& !parameterName.toLowerCase().equals("output")
					&& !parameterName.toLowerCase().equals("apikey")) {
				try {
					String parameterValue = URLDecoder.decode(context.getRequest().getParameter(parameterName),"UTF-8");
					System.out.println(parameterName + ":::" + parameterValue );
					jsonRequest.put(parameterName, parameterValue);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		context.setJsonRequestObject(jsonRequest);
	}

}
